class InferenceEngine

  def initialize
    @sentence = []
    @knowledge = {}
    @question = false
  end

  def learn phrase
    sentence = []
    @question = phrase.include?("?")
    eval phrase.downcase
  end

  def method_missing(m, *args, &block)
    if !args.empty? and args.first.class == Symbol
      sentence << args.first
    end
    method = m.to_s
    method = method.gsub("?", "")
    method = method[0, method.size - 1] if (method[method.size - 1, method.size - 1] == "s")
    method.to_sym
  end

  def are word
    return sentence << word if afirmation?
    "Yes" if question? and knowledge[sentence.last] == sentence.first
  end

  def all word
    return sentence << word if question?
    knowledge.store(word, sentence.first) if afirmation?
    "Ok"
  end

  private

    def afirmation?
      !@question
    end

    def question?
      @question
    end

    def knowledge
      @knowledge
    end

    def sentence
      @sentence
    end
end

